﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.WebControls;
using System.Data;

namespace MII_FIF.Layouts.MII_FIF.DataCabang
{
    public partial class ViewDataCabang : LayoutsPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Generic.IsUserInGroup(Configuration.DataCabangGroupName))
            {
                btnAdd.Click += btnAdd_Click;
                GridDataCabang.RowCommand += GridDataCabang_RowCommand;
                GridDataCabang.PageIndexChanging += GridDataCabang_PageIndexChanging;
                //((Label)Header.FindControl("lblHeader")).Text = "View Data Cabang";
                if (!IsPostBack)
                {
                    load();
                }
            }
            else
            {
                Response.Redirect(Generic.GenLink("/"));
            }
        }

        void GridDataCabang_PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)
        {
            GridDataCabang.DataSource = ViewState["Cabang"];
            GridDataCabang.PageIndex = e.NewPageIndex;
            GridDataCabang.DataBind();
        }

        void GridDataCabang_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            if (e.CommandName.ToLower() == "view")
            {
                Response.Redirect(Generic.GenLink("/_layouts/Mii_FIF/DataCabang/FormDataCabang.aspx?ID=" + e.CommandArgument));
            }
        }

        void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect(Generic.GenLink("/_layouts/Mii_FIF/DataCabang/FormDataCabang.aspx"));
        }

        void load()
        {
            InventoryManagement.Data_Cabang Cabang = new InventoryManagement.Data_Cabang();
            Cabang.wfStatus = word.Approved;
            ViewState["Cabang"] = Cabang.SelectByParam();
            DataTable DT = (DataTable)ViewState["Cabang"];
            ViewState["Cabang"] = Generic.SortDataTable("NamaCabang", word.Ascending, DT);
            GridDataCabang.DataSource = ViewState["Cabang"];
            GridDataCabang.DataBind();
        }
    }
}
